import { _decorator, Collider, Component, EventKeyboard, Input, input, KeyCode, Node, RigidBody, v3 } from 'cc';
import { EventManager, MyEvent } from '../AshFramework/Managers/EventManager';
import { DIR } from '../AshFramework/Managers/InputManager';
const { ccclass, property } = _decorator;

@ccclass('Hero')
export class Hero extends Component {

    @property
    Speed: number = 1000;

    RigidBody: RigidBody = null;
    Collider: Collider = null;

    private _dirX: number = 0;
    private _dirY: number = 0;

    protected onLoad(): void {
        this.RigidBody = this.getComponent(RigidBody);
        this.Collider = this.getComponent(Collider);

        EventManager.on(MyEvent.MOVE, this.setDir, this);
    }

    protected update(dt: number): void {
        this.RigidBody.setLinearVelocity(v3(this._dirX * dt * this.Speed, this._dirY * dt * this.Speed, 0));
    }

    setDir(dir: DIR, num: number) {
        if (dir == DIR.ROW) {
            this._dirX = num;
        } else if (dir == DIR.COL) {
            this._dirY = num;
        }
    }

}


